## RDataFrame to RMatrix.  

"""
<name>RDataFrame to RMatrix</name>
<description>Converts an RDataFrame an RMatrix signal.  This is useful when using functions that expect RMatrix signals.  The RMatrix to RDataFrame conversion happens naturally.</description>
<tags>Data Conversion</tags>
<RFunctions></RFunctions>
<icon></icon>
"""


from OWRpy import *
# import OWGUI
import signals
import redRGUI 


class RDataFrameToRMatrix(OWRpy):
    def __init__(self, parent=None, signalManager=None):
        OWRpy.__init__(self, parent, signalManager, 'RDataFrameToRMatrix')
        self.setRvariableNames(["conversionMatrix"])
        self.inputs = [('Data', signals.RDataFrame, self.gotData)]
        self.outputs = [('Data', signals.RMatrix)]
        
        ### GUI ###
        self.infoArea = redRGUI.textEdit(self.controlArea)
        self.infoArea.setHtml('Data not yet processed')
        
    def gotData(self, data):
        if data:
            ### start the conversion ###
            self.R(self.Rvariables['conversionMatrix']+'<-as.matrix('+data.getData()+')')
            
            newData = signals.RMatrix(data = self.Rvariables['conversionMatrix'], parent = data.getData())
            self.rSend('Data', newData)
            self.infoArea.clear()
            
            self.infoArea.setHtml('Your data has been processed. It looks like this now:</br></br><pre>'+str(self.R('str('+newData.getData()+')'))+'</pre>')
        else:
            self.infoArea.setHtml('No data to process')